package com.example.paopao.consumer.memer.controller;

import com.example.paopao.common.pojo.security.CurrenPrincipal;
import com.example.paopao.common.web.JsonResult;
import com.example.paopao.consumer.memer.pojo.dto.ReleaseAddNewDTO;
import com.example.paopao.consumer.memer.pojo.temp.ReleaseWorkTemp;
import com.example.paopao.consumer.memer.service.ReleaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/release/")
@Api(tags = "6.发布交易")
public class ReleaseController {

    @Autowired
    private ReleaseService releaseService;

    @ApiOperation("添加交易")
    @PostMapping("addNew")
    public JsonResult addNew(@RequestBody ReleaseAddNewDTO releaseWorkDTO,
                             @AuthenticationPrincipal CurrenPrincipal currenPrincipal){
        System.out.println(releaseWorkDTO);
        ReleaseWorkTemp releaseWorkTemp=new ReleaseWorkTemp();
        BeanUtils.copyProperties(releaseWorkDTO,releaseWorkTemp);
        releaseWorkTemp.setUserId(currenPrincipal.getUserId());
        releaseWorkTemp.setUsername(currenPrincipal.getUsername());
        releaseService.addNew(releaseWorkTemp);
        return JsonResult.ok();
    }

    @ApiOperation("获取交易详细")
    @GetMapping("release-detail")
    public JsonResult getRelease(){
        return JsonResult.ok(releaseService.getTranDetail());
    }
}
